package HomeWork.Exception;

public class Bank {
    private double money = 50000;

    public static class MoneyOutOfBoundsException extends RuntimeException {
        public MoneyOutOfBoundsException() {
        }

        public MoneyOutOfBoundsException(String message) {
            super(message);
        }

        public static void checkDrownMoney(Bank b, double money){
            if (money < 0){
                throw new IllegalArgumentException("您输入的金额不合法！");
            }
            if (b.money < money){
                throw new MoneyOutOfBoundsException("您的余额不足！");
            }
        }

        private static void checkSaveMoney(Bank b, double money) {
            if (money < 0){
                throw new IllegalArgumentException("您输入的金额不合法！");
            }
        }
    }


    public void drownMoney (double money){
        MoneyOutOfBoundsException.checkDrownMoney(this,money);
        this.money -= money;
        System.out.println("用户输入取款金额：" + money + ",展示剩余金额为：" + this.money);
    }

    public void saveMoney(double money){
        MoneyOutOfBoundsException.checkSaveMoney(this,money);
        this.money += money;
        System.out.println("用户输入存款金额：" + money + ",展示剩余金额为：" + this.money);
    }

    public Bank() {
    }

    public Bank(double money) {
        this.money = money;
    }

    /**
     * 获取
     * @return money
     */
    public double getMoney() {
        return money;
    }

    /**
     * 设置
     * @param money
     */
    public void setMoney(double money) {
        this.money = money;
    }

    public String toString() {
        return "Bank{money = " + money + "}";
    }
}
